package com.sqx.modules.brand.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.brand.entity.Brand;
import com.sqx.modules.brand.service.BrandService;
import com.sqx.modules.goods.dao.GoodsDao;
import com.sqx.modules.goods.entity.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description：TODO
 * @author： qiao
 * @create： 2024/9/14 17:29
 */
@RestController
@RequestMapping("/admin/brand/")
@Api(value = "品牌相关-管理端",tags = {"品牌相关-管理端"})
public class AdminBrandController {

    @Autowired
    private BrandService brandService;
    @Autowired
    private GoodsDao goodsDao;

    @PostMapping("addBrand")
    @ApiOperation("添加或修改品牌")
    public Result addBrand(Brand brand){
        return brandService.addBrand(brand);
    }

    @PostMapping("deleteBrand")
    @ApiOperation("删除品牌分类")
    public Result deleteBrand(@ApiParam(value ="二手物品品牌分类表id")Long id){
        List<Goods> goodsList = goodsDao.selectList(new QueryWrapper<Goods>().eq("brand_id",id));
        if (!goodsList.isEmpty()){
            return Result.error("该品牌下有关联，请勿删除");
        }
        return brandService.deleteBrand(id);
    }

    @GetMapping("getBrandList")
    @ApiOperation("获取品牌列表")
    public Result getBrandList(@ApiParam(value = "页码") Integer page,
                               @ApiParam(value = "条数") Integer limit,
                               @ApiParam(value = "二手物品品牌分类表") Brand brand){
        return Result.success().put("data",brandService.getBrandList(page,limit,brand));
    }

    @GetMapping("selectById")
    @ApiOperation("根据id查询品牌")
    public Result selectById(@ApiParam(value ="二手物品品牌分类表id")Long id){
        return brandService.selectById(id);
    }

    @GetMapping("selectByLabelId")
    @ApiOperation("根据分类id查询品牌")
    public Result selectByTypeId(@ApiParam(value ="标签分类id")Long labelId,
                                 @ApiParam(value = "是否热门品牌：1是热门品牌")Integer isHot){
        return brandService.selectByTypeId(labelId,isHot);
    }

    @GetMapping("copyBrandListByRecycle")
    @ApiOperation("将回收类型以及品牌、物品、规格复制到普通商品类型")
    public Result copyBrandListByRecycle(@ApiParam(value ="标签分类id")Long labelId,
                                         @ApiParam(value ="二手物品品牌id")Long brandId){
        return brandService.copyBrandListByRecycle(labelId,brandId);
    }

    @GetMapping("copyBrandListByOrdinary")
    @ApiOperation("将普通类型以及品牌、物品、规格复制到回收商品类型")
    public Result copyBrandListByOrdinary(@ApiParam(value ="标签分类id")Long labelId,
                                          @ApiParam(value ="二手物品品牌id")Long brandId){
        return brandService.copyBrandListByOrdinary(labelId,brandId);
    }

}
